% Produced by CVXGEN, 2012-08-15 14:12:46 -0700.
% CVXGEN is Copyright (C) 2006-2011 Jacob Mattingley, jem@cvxgen.com.
% The code in this file is Copyright (C) 2006-2011 Jacob Mattingley.
% CVXGEN, or solvers produced by CVXGEN, cannot be used for commercial
% applications without prior written permission from Jacob Mattingley.

% Filename: cvxsolve.m.
% Description: Solution file, via cvx, for use with sample.m.

function [vars, status] = cvxsolve(params, settings)

A = params.A;
B = params.B;
Q = params.Q;
R = params.R;
u_max = params.u_max;
u_min = params.u_min;
x_0 = params.x_0;

cvx_begin
  % Caution: automatically generated by cvxgen. May be incorrect.
  variable u_0(20, 1);
  variable x_1(50, 1);
  variable u_1(20, 1);
  variable x_2(50, 1);
  variable u_2(20, 1);
  variable x_3(50, 1);
  variable u_3(20, 1);
  variable x_4(50, 1);
  variable u_4(20, 1);
  variable x_5(50, 1);
  variable u_5(20, 1);
  variable x_6(50, 1);
  variable u_6(20, 1);
  variable x_7(50, 1);
  variable u_7(20, 1);
  variable x_8(50, 1);
  variable u_8(20, 1);
  variable x_9(50, 1);
  variable u_9(20, 1);
  variable x_10(50, 1);
  variable u_10(20, 1);
  variable x_11(50, 1);
  variable u_11(20, 1);
  variable x_12(50, 1);
  variable u_12(20, 1);
  variable x_13(50, 1);
  variable u_13(20, 1);
  variable x_14(50, 1);
  variable u_14(20, 1);
  variable x_15(50, 1);
  variable u_15(20, 1);
  variable x_16(50, 1);
  variable u_16(20, 1);
  variable x_17(50, 1);
  variable u_17(20, 1);
  variable x_18(50, 1);
  variable u_18(20, 1);
  variable x_19(50, 1);
  variable u_19(20, 1);
  variable x_20(50, 1);
  variable u_20(20, 1);
  variable x_21(50, 1);
  variable u_21(20, 1);
  variable x_22(50, 1);
  variable u_22(20, 1);
  variable x_23(50, 1);
  variable u_23(20, 1);
  variable x_24(50, 1);
  variable u_24(20, 1);
  variable x_25(50, 1);
  variable u_25(20, 1);
  variable x_26(50, 1);
  variable u_26(20, 1);
  variable x_27(50, 1);
  variable u_27(20, 1);
  variable x_28(50, 1);
  variable u_28(20, 1);
  variable x_29(50, 1);
  variable u_29(20, 1);
  variable x_30(50, 1);
  variable u_30(20, 1);

  minimize(quad_form(x_0, Q) + quad_form(u_0, R) + quad_form(x_1, Q) + quad_form(u_1, R) + quad_form(x_2, Q) + quad_form(u_2, R) + quad_form(x_3, Q) + quad_form(u_3, R) + quad_form(x_4, Q) + quad_form(u_4, R) + quad_form(x_5, Q) + quad_form(u_5, R) + quad_form(x_6, Q) + quad_form(u_6, R) + quad_form(x_7, Q) + quad_form(u_7, R) + quad_form(x_8, Q) + quad_form(u_8, R) + quad_form(x_9, Q) + quad_form(u_9, R) + quad_form(x_10, Q) + quad_form(u_10, R) + quad_form(x_11, Q) + quad_form(u_11, R) + quad_form(x_12, Q) + quad_form(u_12, R) + quad_form(x_13, Q) + quad_form(u_13, R) + quad_form(x_14, Q) + quad_form(u_14, R) + quad_form(x_15, Q) + quad_form(u_15, R) + quad_form(x_16, Q) + quad_form(u_16, R) + quad_form(x_17, Q) + quad_form(u_17, R) + quad_form(x_18, Q) + quad_form(u_18, R) + quad_form(x_19, Q) + quad_form(u_19, R) + quad_form(x_20, Q) + quad_form(u_20, R) + quad_form(x_21, Q) + quad_form(u_21, R) + quad_form(x_22, Q) + quad_form(u_22, R) + quad_form(x_23, Q) + quad_form(u_23, R) + quad_form(x_24, Q) + quad_form(u_24, R) + quad_form(x_25, Q) + quad_form(u_25, R) + quad_form(x_26, Q) + quad_form(u_26, R) + quad_form(x_27, Q) + quad_form(u_27, R) + quad_form(x_28, Q) + quad_form(u_28, R) + quad_form(x_29, Q) + quad_form(u_29, R) + quad_form(x_30, Q) + quad_form(u_30, R));
  subject to
    x_1 == A*x_0 + B*u_0;
    x_2 == A*x_1 + B*u_1;
    x_3 == A*x_2 + B*u_2;
    x_4 == A*x_3 + B*u_3;
    x_5 == A*x_4 + B*u_4;
    x_6 == A*x_5 + B*u_5;
    x_7 == A*x_6 + B*u_6;
    x_8 == A*x_7 + B*u_7;
    x_9 == A*x_8 + B*u_8;
    x_10 == A*x_9 + B*u_9;
    x_11 == A*x_10 + B*u_10;
    x_12 == A*x_11 + B*u_11;
    x_13 == A*x_12 + B*u_12;
    x_14 == A*x_13 + B*u_13;
    x_15 == A*x_14 + B*u_14;
    x_16 == A*x_15 + B*u_15;
    x_17 == A*x_16 + B*u_16;
    x_18 == A*x_17 + B*u_17;
    x_19 == A*x_18 + B*u_18;
    x_20 == A*x_19 + B*u_19;
    x_21 == A*x_20 + B*u_20;
    x_22 == A*x_21 + B*u_21;
    x_23 == A*x_22 + B*u_22;
    x_24 == A*x_23 + B*u_23;
    x_25 == A*x_24 + B*u_24;
    x_26 == A*x_25 + B*u_25;
    x_27 == A*x_26 + B*u_26;
    x_28 == A*x_27 + B*u_27;
    x_29 == A*x_28 + B*u_28;
    x_30 == A*x_29 + B*u_29;
    u_0 <= u_max;
    u_1 <= u_max;
    u_2 <= u_max;
    u_3 <= u_max;
    u_4 <= u_max;
    u_5 <= u_max;
    u_6 <= u_max;
    u_7 <= u_max;
    u_8 <= u_max;
    u_9 <= u_max;
    u_10 <= u_max;
    u_11 <= u_max;
    u_12 <= u_max;
    u_13 <= u_max;
    u_14 <= u_max;
    u_15 <= u_max;
    u_16 <= u_max;
    u_17 <= u_max;
    u_18 <= u_max;
    u_19 <= u_max;
    u_20 <= u_max;
    u_21 <= u_max;
    u_22 <= u_max;
    u_23 <= u_max;
    u_24 <= u_max;
    u_25 <= u_max;
    u_26 <= u_max;
    u_27 <= u_max;
    u_28 <= u_max;
    u_29 <= u_max;
    u_30 <= u_max;
    u_0 >= u_min;
    u_1 >= u_min;
    u_2 >= u_min;
    u_3 >= u_min;
    u_4 >= u_min;
    u_5 >= u_min;
    u_6 >= u_min;
    u_7 >= u_min;
    u_8 >= u_min;
    u_9 >= u_min;
    u_10 >= u_min;
    u_11 >= u_min;
    u_12 >= u_min;
    u_13 >= u_min;
    u_14 >= u_min;
    u_15 >= u_min;
    u_16 >= u_min;
    u_17 >= u_min;
    u_18 >= u_min;
    u_19 >= u_min;
    u_20 >= u_min;
    u_21 >= u_min;
    u_22 >= u_min;
    u_23 >= u_min;
    u_24 >= u_min;
    u_25 >= u_min;
    u_26 >= u_min;
    u_27 >= u_min;
    u_28 >= u_min;
    u_29 >= u_min;
    u_30 >= u_min;
cvx_end

vars.u_0 = u_0;
vars.u_1 = u_1;
vars.u{1} = u_1;

vars.u_2 = u_2;
vars.u{2} = u_2;

vars.u_3 = u_3;
vars.u{3} = u_3;

vars.u_4 = u_4;
vars.u{4} = u_4;

vars.u_5 = u_5;
vars.u{5} = u_5;

vars.u_6 = u_6;
vars.u{6} = u_6;

vars.u_7 = u_7;
vars.u{7} = u_7;

vars.u_8 = u_8;
vars.u{8} = u_8;

vars.u_9 = u_9;
vars.u{9} = u_9;

vars.u_10 = u_10;
vars.u{10} = u_10;

vars.u_11 = u_11;
vars.u{11} = u_11;

vars.u_12 = u_12;
vars.u{12} = u_12;

vars.u_13 = u_13;
vars.u{13} = u_13;

vars.u_14 = u_14;
vars.u{14} = u_14;

vars.u_15 = u_15;
vars.u{15} = u_15;

vars.u_16 = u_16;
vars.u{16} = u_16;

vars.u_17 = u_17;
vars.u{17} = u_17;

vars.u_18 = u_18;
vars.u{18} = u_18;

vars.u_19 = u_19;
vars.u{19} = u_19;

vars.u_20 = u_20;
vars.u{20} = u_20;

vars.u_21 = u_21;
vars.u{21} = u_21;

vars.u_22 = u_22;
vars.u{22} = u_22;

vars.u_23 = u_23;
vars.u{23} = u_23;

vars.u_24 = u_24;
vars.u{24} = u_24;

vars.u_25 = u_25;
vars.u{25} = u_25;

vars.u_26 = u_26;
vars.u{26} = u_26;

vars.u_27 = u_27;
vars.u{27} = u_27;

vars.u_28 = u_28;
vars.u{28} = u_28;

vars.u_29 = u_29;
vars.u{29} = u_29;

vars.u_30 = u_30;
vars.u{30} = u_30;

vars.x_1 = x_1;
vars.x{1} = x_1;

vars.x_2 = x_2;
vars.x{2} = x_2;

vars.x_3 = x_3;
vars.x{3} = x_3;

vars.x_4 = x_4;
vars.x{4} = x_4;

vars.x_5 = x_5;
vars.x{5} = x_5;

vars.x_6 = x_6;
vars.x{6} = x_6;

vars.x_7 = x_7;
vars.x{7} = x_7;

vars.x_8 = x_8;
vars.x{8} = x_8;

vars.x_9 = x_9;
vars.x{9} = x_9;

vars.x_10 = x_10;
vars.x{10} = x_10;

vars.x_11 = x_11;
vars.x{11} = x_11;

vars.x_12 = x_12;
vars.x{12} = x_12;

vars.x_13 = x_13;
vars.x{13} = x_13;

vars.x_14 = x_14;
vars.x{14} = x_14;

vars.x_15 = x_15;
vars.x{15} = x_15;

vars.x_16 = x_16;
vars.x{16} = x_16;

vars.x_17 = x_17;
vars.x{17} = x_17;

vars.x_18 = x_18;
vars.x{18} = x_18;

vars.x_19 = x_19;
vars.x{19} = x_19;

vars.x_20 = x_20;
vars.x{20} = x_20;

vars.x_21 = x_21;
vars.x{21} = x_21;

vars.x_22 = x_22;
vars.x{22} = x_22;

vars.x_23 = x_23;
vars.x{23} = x_23;

vars.x_24 = x_24;
vars.x{24} = x_24;

vars.x_25 = x_25;
vars.x{25} = x_25;

vars.x_26 = x_26;
vars.x{26} = x_26;

vars.x_27 = x_27;
vars.x{27} = x_27;

vars.x_28 = x_28;
vars.x{28} = x_28;

vars.x_29 = x_29;
vars.x{29} = x_29;

vars.x_30 = x_30;
vars.x{30} = x_30;

status.cvx_status = cvx_status;

% Provide a drop-in replacement for csolve.
status.optval = cvx_optval;
status.converged = strcmp(cvx_status, 'Solved');
